package com.power.sifa.correction.model;


import cn.hutool.core.util.ObjectUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.plf.common.domain.YesNo;
import com.plf.core.common.annotations.FieldEnumText;
import com.plf.core.common.domain.BaseModel;
import com.power.sifa.correction.model.pojo.bo.Crc_personExcelBO;
import com.power.sifa.statistics.model.enumeration.AddressAdidEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import javax.persistence.*;
import java.io.Serializable;
import java.time.ZoneId;
import java.util.Date;
import java.util.Map;
import java.util.regex.Pattern;

/**
 * 社区矫正人员信息实体类
 */

@Entity
@ApiModel(value = "社区矫正人员信息")
@Data
@Table(name = "Crc_person", schema = "sfapprove")
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
//@IdClass(Crc_person.Crc_personPK.class) 用于复合组件
public class Crc_person extends BaseModel implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @Setter(AccessLevel.NONE)
    @ApiModelProperty(value = "序号")
    private String id;

    @Column(nullable = false)
    @ApiModelProperty(value = "姓名")
    private String name;

    @ApiModelProperty(value = "性别")
    private Integer gender;

    @ApiModelProperty(value = "矫正类别")
    private Integer crctype;

    @ApiModelProperty(value = "罪名")
    private String crime;

    @Column(nullable = false)
    @ApiModelProperty(value = "身份证号")
    private String cardno;

    @ApiModelProperty(value = "矫正期限")
    private String timelong;

    @ApiModelProperty(value = "矫正开始日期")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date startdate;

    @ApiModelProperty(value = "矫正结束日期")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date enddate;

    @ApiModelProperty(value = "头像")
    private String avatar;

    @ApiModelProperty(value = "删除标记")
    private Integer deleted;

    @ApiModelProperty(value = "行政区划代码")
    private String adid;

    @ApiModelProperty(value = "所属司法所id")
    private String deptid;

    @ApiModelProperty(value = "管控级别")
    private Integer controltype;

    @ApiModelProperty(value = "联系号码")
    private String phone;

    @ApiModelProperty(value = "民族")
    private Integer nation;

    @ApiModelProperty(value = "重点人员")
    private Integer focus = YesNo.NO;

    @ApiModelProperty(value = "文化程度")
    private Integer culture;

    @ApiModelProperty(value = "出生日期")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date birthym;

    @ApiModelProperty(value = "入矫日期")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date enterdate;

    @ApiModelProperty(value = "运营商类型")
    private Integer operators;

    @ApiModelProperty(value = "家庭住址")
    private String addr;

    @ApiModelProperty(value = "户籍信息")
    private String domicile;

    @ApiModelProperty(value = "国籍")
    private Integer nationality;

    @ApiModelProperty(value = "户口类型")
    private Integer housetype;

    @ApiModelProperty(value = "原职业")
    private String oricareer;

    @ApiModelProperty(value = "就业就学")
    private Integer perform;

    @ApiModelProperty(value = "原政治面貌")
    private Integer politics;

    @ApiModelProperty(value = "婚姻状况")
    private Integer marriage;

    @ApiModelProperty(value = "是否有传染史")
    private Integer isinfect;

    @ApiModelProperty(value = "宗教信仰")
    private String religion;

    @ApiModelProperty(value = "原判起日")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date oristartdate;

    @ApiModelProperty(value = "原判止日")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date orienddata;

    @ApiModelProperty(value = "刑种")
    private Integer penalty;

    @ApiModelProperty(value = "入矫类别")
    private Integer entertype;

    @ApiModelProperty(value = "报到时间")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date reportdate;

    @ApiModelProperty(value = "操作")
    private String operation;

    @ApiModelProperty(value = "决定机关类型")
    private Integer organtype;

    @ApiModelProperty(value = "决定机关名称")
    private String organname;

    @ApiModelProperty(value = "报到情况")
    private String reportsit;

    @ApiModelProperty(value = "人员编号(部)")
    private String troopid;

    @ApiModelProperty(value = "布控开始时间")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date constartdate;

    @ApiModelProperty(value = "布控结束时间")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date conenddate;

    @Column(nullable = false)
    @ApiModelProperty(value = "身份证号")
    private String cardnoIndex;

    /**
     * 司法所名称
     */
    @Transient
    private String deptname;

    /**
     * 头像url地址
     */
    @Transient
    private String avatarUrl;

    /**
     * 性别文本
     */
    @Transient
    @FieldEnumText(eum = "Tp_gender", valuefield = "gender")
    private String gender_text;

    /**
     * 矫正类别文本
     */
    @Transient
    @FieldEnumText(eum = "Tp_crc_user", valuefield = "crctype")
    private String crctype_text;

    /**
     * 管控级别文本
     */
    @Transient
    @FieldEnumText(eum = "Tp_crc_ctrl", valuefield = "controltype")
    private String controltype_text;

    /**
     * 民族文本
     */
    @Transient
    @FieldEnumText(eum = "Tp_nation", valuefield = "nation")
    private String nation_text;

    /**
     * 重点人员文本
     */
    @Transient
    @FieldEnumText(eum = "yesNo", valuefield = "focus")
    private String focus_text;

    /**
     * 文化程度文本
     */
    @Transient
    @FieldEnumText(eum = "Per_edu", valuefield = "culture")
    private String culture_text;

    /**
     * 政治面貌文本
     */
    @Transient
    @FieldEnumText(eum = "Per_politics", valuefield = "politics")
    private String politics_text;

    /**
     * 国籍文本
     */
    @Transient
    @FieldEnumText(eum = "Per_nationality", valuefield = "nationality")
    private String nationality_text;

    /**
     * 户口类型文本
     */
    @Transient
    @FieldEnumText(eum = "Per_housetype", valuefield = "housetype")
    private String housetype_text;


    /**
     * 婚姻状况文本
     */
    @Transient
    @FieldEnumText(eum = "Per_marry", valuefield = "marriage")
    private String marriage_text;


    /**
     * 就业就学文本
     */
    @Transient
    @FieldEnumText(eum = "Per_perform", valuefield = "perform")
    private String perform_text;

    /**
     * 是否有传染史文本
     */
    @Transient
    @FieldEnumText(eum = "Tp_yesno", valuefield = "isinfect")
    private String isinfect_text;

    /**
     * 刑种文本
     */
    @Transient
    @FieldEnumText(eum = "Tp_crc_penalty", valuefield = "penalty")
    private String penalty_text;

    /**
     * 入矫类别文本
     */
    @Transient
    @FieldEnumText(eum = "Tp_crc_enter", valuefield = "entertype")
    private String entertype_text;

    @Transient
    @FieldEnumText(eum = "Tp_organtype", valuefield = "organtype")
    private String organtype_text;

    @PrePersist
    public void generateCustomId() {
        if (this.id != null) {
            String regex = "[A-Z]+-\\d{4}";
            Pattern pattern = Pattern.compile(regex);
            boolean isMatch = pattern.matcher(this.id).matches();
            if (isMatch) {
                return;
            }
        }
        String ad = null;
        if (this.adid != null) {
            ad = AddressAdidEnum.getTypeNameByValue(this.adid);
        }
        this.id = ad + "-" + this.id;
    }

    public Crc_person(Crc_personExcelBO excelBO) {
        this.troopid = excelBO.getTroopid();
        this.id = (ObjectUtil.isNotNull(excelBO.getId())) ? excelBO.getId() : null;
        this.name = excelBO.getName();
        this.startdate = ObjectUtil.isNotEmpty(excelBO.getStartdate()) ?
                Date.from(excelBO.getStartdate().atStartOfDay(ZoneId.systemDefault()).toInstant()) : null;
        this.enddate = ObjectUtil.isNotEmpty(excelBO.getEnddate()) ?
                Date.from(excelBO.getEnddate().atStartOfDay(ZoneId.systemDefault()).toInstant()) : null;
        this.birthym = ObjectUtil.isNotEmpty(excelBO.getBirthym()) ?
                Date.from(excelBO.getBirthym().atStartOfDay(ZoneId.systemDefault()).toInstant()) : null;
        this.enterdate = ObjectUtil.isNotEmpty(excelBO.getEnterdate()) ?
                Date.from(excelBO.getEnterdate().atStartOfDay(ZoneId.systemDefault()).toInstant()) : null;
        this.phone = excelBO.getPhone();
        this.addr = excelBO.getAddr();
        this.domicile = excelBO.getDomicile();
        this.cardno = excelBO.getCardno();
        this.oricareer = excelBO.getOricareer();
        this.religion = excelBO.getReligion();
        this.oristartdate = ObjectUtil.isNotEmpty(excelBO.getOristartdate()) ?
                Date.from(excelBO.getOristartdate().atStartOfDay(ZoneId.systemDefault()).toInstant()) : null;
        this.orienddata = ObjectUtil.isNotEmpty(excelBO.getOrienddata()) ?
                Date.from(excelBO.getOrienddata().atStartOfDay(ZoneId.systemDefault()).toInstant()) : null;
        this.timelong = excelBO.getTimelong();
        this.reportdate = ObjectUtil.isNotEmpty(excelBO.getReportdate()) ?
                Date.from(excelBO.getReportdate().atStartOfDay(ZoneId.systemDefault()).toInstant()) : null;
        this.reportsit = excelBO.getReportsit();
        this.crime = excelBO.getCrime();
        this.operation = excelBO.getOperation();
        this.organname = excelBO.getOrganname();
        this.deleted = 0;
    }

    public Map<String, Object> parseMap() {
        return null;
    }

    public String getId() {
        return id;
    }

    public void setId(Serializable id) {
        this.id = (String) id;
    }

    public Serializable getPrimaryKey() {
        return id;
        // return new Crc_personPK(id, id2); 用于复合主键，请手动创建内部静态类
    }

    public void setPrimaryKey(Serializable key) {
        this.id = (String) key;

        //Crc_personPK pk = (Crc_personPK) key; 用于复合主键
        //this.id = pk.getId();
        //this.id2 = pk.getId2();
    }

}
